#ifndef __UTIL_H__
#define __UTIL_H__
#include <time.h> 



static int curYearMonthStr(std::string& str)
{
	char now[16] = { 0 };
	time_t tt = ::time(NULL);
	struct tm* ttime;
	ttime = ::localtime(&tt);
	::strftime(now, sizeof(now), "%Y%m", ttime);
	str = now;

	return 0;
}

static int curYearMonthStr(const time_t tt, std::string& str)
{
	char now[16] = { 0 };
	struct tm* ttime;
	ttime = ::localtime(&tt);
	::strftime(now, sizeof(now), "%Y%m", ttime);
	str = now;

	return 0;
}

static int yearMonthStr(const time_t tt, const int timezoneinmin, std::string& str)
{
	char sznow[16] = { 0 };
	time_t ltt = tt + (timezoneinmin*60);
	struct tm* ttime;
	ttime = ::gmtime(&ltt);
	::strftime(sznow, sizeof(sznow), "%Y%m", ttime);
	str = sznow;

	return 0;
}

static void timestampToymd(const time_t tt, const int timezoneinmin, unsigned int& ymd)
{
	time_t ltt = tt + (timezoneinmin * 60);
	struct tm* ttime = ::gmtime(&ltt);
	ymd = (ttime->tm_year + 1900) * 10000 + (ttime->tm_mon + 1) * 100 + ttime->tm_mday;

	return;
}

static int tableName(const unsigned int game, std::string& ym, const unsigned int uid, const unsigned int mod, std::string& name)
{
	ostringstream oss;
	oss << "gamerecord_" << game << "_" << ym << "_" << uid % mod;

	name = oss.str();
	return 0;
}
#endif